function gMapHelper() {
	
	this.isIvalidGMap = function (){
		return !(!window.GBrowserIsCompatible || !GBrowserIsCompatible());
	}
	
	this.defaultSetting = function(){
		return this.isIvalidGMap()?
				{
			    	geocoder = new GClientGeocoder();
			        address: '',
			        latitude: 0,
			        longitude: 0,
			        zoom: 1,
			        gKeyboardHandler: 0,
			        disableDragging: 0,
			        centerInfo: '',
			        markers: [],
			        controls: [],
			        scrollwheel: true,
			        maptype: G_NORMAL_MAP,
			        html_prepend: '<div class="gmap_marker">',
			        html_append: '</div>',
			        icon: {
			            image: "http://www.google.com/mapfiles/marker.png",
			            shadow: "http://www.google.com/mapfiles/shadow50.png",
			            iconsize: [20, 34],
			            shadowsize: [37, 34],
			            iconanchor: [9, 34],
			            infowindowanchor: [9, 2]
			        }
			    }:{};
	}
	
	this.defaultGIcon = function(){
		if(!this.isIvalidGMap()){
			return false;
		}
    	var opts = this.defaultSetting();
		var gicon = new GIcon();
        gicon.image = opts.icon.image;
        gicon.shadow = opts.icon.shadow;
        gicon.iconSize = ($.isArray(opts.icon.iconsize)) ? new GSize(opts.icon.iconsize[0], opts.icon.iconsize[1]) : opts.icon.iconsize;
        gicon.shadowSize = ($.isArray(opts.icon.shadowsize)) ? new GSize(opts.icon.shadowsize[0], opts.icon.shadowsize[1]) : opts.icon.shadowsize;
        gicon.iconAnchor = ($.isArray(opts.icon.iconanchor)) ? new GPoint(opts.icon.iconanchor[0], opts.icon.iconanchor[1]) : opts.icon.iconanchor;
        gicon.infoWindowAnchor = ($.isArray(opts.icon.infowindowanchor)) ? new GPoint(opts.icon.infowindowanchor[0], opts.icon.infowindowanchor[1]) : opts.icon.infowindowanchor;
        return gicon;
	}
	
	this.gIcon = function(options){
		if(!this.isIvalidGMap()){
			return false;
		}
		var gicon = new GIcon();
        if (options != null && $.isPlainObject(options)) {
            gicon.image = options.image;
            gicon.shadow = options.shadow;
            gicon.iconSize = ($.isArray(options.iconsize)) ? new GSize(options.iconsize[0], options.iconsize[1]) : options.iconsize;
            gicon.shadowSize = ($.isArray(options.shadowsize)) ? new GSize(options.shadowsize[0], options.shadowsize[1]) : options.shadowsize;
            gicon.iconAnchor = ($.isArray(options.iconanchor)) ? new GPoint(options.iconanchor[0], options.iconanchor[1]) : options.iconanchor;
            gicon.infoWindowAnchor = ($.isArray(options.infowindowanchor)) ? new GPoint(options.infowindowanchor[0], options.infowindowanchor[1]) : options.infowindowanchor;
        } else {
        	gicon = this.defaultGIcon();
        }
        return gicon;
	}
	
	$.pointMaker = function(gpoint,gicon,html){
		var gmarker = new GMarker(gpoint, gicon);
        if (marker.html) {
            gmarker.bindInfoWindowHtml(opts.html_prepend +
            marker.html +
            opts.html_append);
        }
        if (marker.html && marker.popup) {
            gmarker.openInfoWindowHtml(opts.html_prepend +
            marker.html +
            opts.html_append);
        }
        if (gmarker) {
            $gmap.addOverlay(gmarker);
        }
	}
	$.addMarker = function(makers,$gmap){
		if(!isIvalidGMap){
			return false;
		}
		for (var j = 0; j < markers.length; j++) {
            marker = markers[j];
            var gicon = $.gIcon(marker.icon);
            if (marker.address) {
                if (marker.html == '_address') {
                    marker.html = marker.address;
                }
                $geocoder.getLatLng(marker.address, function(gicon, marker){
                    return function(gpoint){
                        gmarker = new GMarker(gpoint, gicon);
                        if (marker.html) {
                            gmarker.bindInfoWindowHtml(opts.html_prepend +
                            marker.html +
                            opts.html_append);
                        }
                        if (marker.html &&
                        marker.popup) {
                            gmarker.openInfoWindowHtml(opts.html_prepend +
                            marker.html +
                            opts.html_append);
                        }
                        
                        if (gmarker) {
                            $gmap.addOverlay(gmarker);
                        }
                    }
                    
                }(gicon, marker));
            }
            else {
                if (marker.html == '_latlng') {
                    marker.html = marker.latitude + ', ' +
                    marker.longitude;
                }
                gmarker = new GMarker(new GPoint(marker.longitude, marker.latitude), gicon);
                if (marker.html) {
                    gmarker.bindInfoWindowHtml(opts.html_prepend +
                    marker.html +
                    opts.html_append);
                }
                if (marker.html && marker.popup) {
                    gmarker.openInfoWindowHtml(opts.html_prepend +
                    marker.html +
                    opts.html_append);
                }
                if (gmarker) {
                    $gmap.addOverlay(gmarker);
                }
            }
        }
		
	}

    $.fn.gMap.addAddress = function(address){
		if (!window.GBrowserIsCompatible || !GBrowserIsCompatible()) 
            return this;
        
        var opts = $.extend({}, $.fn.gMap.defaults, options);
		
        $geocoder.getLocations(address, function(response){
            if (!response || response.Status.code != 200) {
                //alert("Status Code:" + response.Status.code);
            }
            else {
                place = response.Placemark[0];
                var point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
                $gmap.setCenter(point, 9);
                var marker = new GMarker(point);
                $gmap.addOverlay(marker);
            }
        });
    }
}
gMapHelper = new gMapHelper();